Skip to content

웹소켓 STOMP 쿠키 기반 인증 도입 및 SEND 커맨드 실시간 검증#231

Merged
Goder-0 merged 3 commits into
mainfrom
feat/#223-websocket-auth-improvement
Jun 18, 2026
Merged

웹소켓 STOMP 쿠키 기반 인증 도입 및 SEND 커맨드 실시간 검증#231
Goder-0 merged 3 commits into
mainfrom
feat/#223-websocket-auth-improvement

Conversation

@ckdals4600

@ckdals4600 ckdals4600 commented May 16, 2026

Copy link
Copy Markdown
Contributor

관련 이슈

PR 설명

  • 기존 웹소켓 통신은 연결(CONNECT) 시점에만 헤더를 통해 인증을 수행하여, 연결 이후 토큰이 만료되거나 비정상적인 SEND 요청이 들어올 때 이를 방어하지 못하는 보안 취약점이 있었습니다.
  • 이를 해결하기 위해 HTTP Handshake 과정에서 쿠키를 통해 토큰을 추출하는 로직을 추가하고, 메시지 발행(SEND) 시점마다 토큰의 유효성을 실시간으로 검증하도록 인증 아키텍처를 크게 개선했습니다.

작업 내용

1. 웹소켓 엔드포인트 보안 정책 강화 (SecurityConstants)

  • 기존 PERMIT_URLS에 포함되어 무조건 허용되던 웹소켓 경로(/ws/chat/**, /ws/link/**)를 제거하여, 기본적인 Spring Security 인증 정책의 보호를 받도록 변경했습니다.

2. 쿠키 기반 Handshake 인터셉터 추가 (WebSocketConfig)

  • 웹소켓 연결 최초 진입점인 HTTP Handshake 단계에서 동작하는 HandshakeInterceptor를 추가했습니다.
  • 클라이언트의 요청 쿠키에서 accessToken을 추출하여 STOMP 세션 정보(attributes)에 저장해 둠으로써, 이후 TCP 통신 단계에서도 토큰 정보에 접근할 수 있도록 하이브리드 인증 기반을 마련했습니다.

3. SEND 커맨드 JWT 실시간 검증 (StompHandler)

  • ChannelInterceptorpreSend 로직을 개선하여, CONNECT뿐만 아니라 SEND 커맨드 유입 시에도 인증을 수행하도록 분기를 확장했습니다.
  • 세션 속성에 저장된 쿠키 토큰(또는 헤더 토큰)을 가져와 만료 여부를 실시간으로 체크(validateAccessToken)하며, 만료되거나 유효하지 않은 토큰으로 메시지를 전송하려 할 경우 MessagingException을 발생시켜 원천 차단합니다.

@ckdals4600 ckdals4600 self-assigned this May 16, 2026
@ckdals4600 ckdals4600 linked an issue May 16, 2026 that may be closed by this pull request
@ckdals4600 ckdals4600 requested review from Goder-0 and minibr May 16, 2026 12:23
@ckdals4600 ckdals4600 force-pushed the feat/#223-websocket-auth-improvement branch from 7ebc66e to 33b06d1 Compare May 20, 2026 10:53
@github-actions

github-actions Bot commented May 20, 2026

Copy link
Copy Markdown

📊 코드 커버리지 리포트

Overall Project 94.21% 🍏

There is no coverage information present for the Files changed

Comment thread src/main/java/com/sofa/linkiving/security/config/StompHandler.java
@Goder-0

Goder-0 commented May 20, 2026

Copy link
Copy Markdown
Contributor

PR에 이슈 번호 연결해주세요.

@ckdals4600 ckdals4600 requested a review from Goder-0 May 22, 2026 14:37
- [WebSocketConfig] HTTP Handshake 시 accessToken 쿠키를 웹소켓 세션으로 복사하는 HandshakeInterceptor 추가
- [StompHandler] STOMP CONNECT 시 세션(쿠키) 토큰과 헤더 토큰을 모두 지원하도록 하이브리드 인증 로직 구현

@Goder-0 Goder-0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

작업이 완료되었다고 판단되어 승인합니다.
한편, 프론트 대응작업으로 Team-SoFa/linkiving#518 이슈를 생성하였습니다. 해당 이슈를 해결하는 PR이 올라온 이후 머지가 되는것이 좋을 것 같습니다.

@Goder-0 Goder-0 merged commit afad075 into main Jun 18, 2026
1 check passed
@ckdals4600 ckdals4600 deleted the feat/#223-websocket-auth-improvement branch June 24, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebSocket 인증 방식 개선

2 participants